<?php

namespace Home\Controller;

class CommentsController extends CommonController {

    public function create() {
        if (!isset($_POST['req'])) {
            return $this->ajaxReturn($this->buildResult(false, 'comment必填'));
        }

        $Comment = D('Comment');
        $comment = json_decode($_POST['req'], true);
        if ($comment = $Comment->create($comment)) {
            if (false === $Comment->add($comment)) {
                return $this->ajaxReturn($this->buildResult(false, $Comment->getDbError()));
            }
        }

        return $this->ajaxReturn($this->buildResult(true, '评论成功'));
    }
}
